<script setup lang="ts">
  import { computed, ref } from 'vue'
  import mobile from './components/mobile.vue'
  import password from './components/password.vue'
  type TitleItem = {
    title: string
    subTitle: string
  }

  // 用来展示数据
  const titleList: TitleItem[] = [
    { title: '验证码登录', subTitle: '密码登录' },
    { title: '密码登录', subTitle: '验证码登录' },
  ]
  // 定义当前的激活选项
  // 0(验证码登录) 1(密码登录)
  const activeIndex = ref(0) // 当前激活的模式
  // 通过计算属性得到显示标题
  const showTitle = computed(() => {
    return titleList[activeIndex.value]
  })
  const changeActive = () => {
    // 0-1 1-1
    activeIndex.value = Math.abs(activeIndex.value - 1)
    // 取绝对值的方式 0 减去1 得-1 =>绝对值 得 1
    // 1 减去1 得 0
  }
</script>
<template>
  <view class="user-login">
    <view class="login-type">
      <view class="title">{{ showTitle.title }}</view>
      <view class="type" @click="changeActive">
        <text>{{ showTitle.subTitle }}</text>
        <uni-icons color="#3c3e42" type="forward" />
      </view>
    </view>
    <!-- 控制显示和隐藏 -->
    <mobile v-if="activeIndex === 0"></mobile>
    <password v-if="activeIndex === 1"></password>
  </view>

  <!-- 社交账号登录 -->
  <view class="social-login">
    <view class="legend">
      <text class="text">其它方式登录</text>
    </view>
    <view class="social-account">
      <view class="icon">
        <uni-icons color="#00b0fb" size="30" type="qq" />
      </view>
      <view class="icon">
        <uni-icons color="#fb6622" size="30" type="weibo" />
      </view>
      <view class="icon">
        <uni-icons color="#07C160" size="30" type="weixin" />
      </view>
    </view>
  </view>
</template>

<style lang="scss">
  .user-login {
    padding: 60rpx;
  }

  .login-type {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    line-height: 1;
    margin: 40rpx 0 80rpx;

    .title {
      font-size: 48rpx;
      color: #121826;
    }

    .type {
      color: #3c3e42;
      font-size: 30rpx;
      display: flex;
      align-items: center;
    }
  }

  .social-login {
    margin-top: 100rpx;
    padding: 0 60rpx;

    .legend {
      height: 40rpx;
      position: relative;
      border-top: 1rpx solid #ebebeb;
    }

    .text {
      position: absolute;
      top: -50%;
      left: 50%;

      font-size: 28rpx;
      color: #999;
      padding: 0 10rpx;
      background-color: #fff;
      transform: translate(-50%);
    }

    .social-account {
      display: flex;
      justify-content: space-evenly;
      margin-top: 40rpx;

      .icon {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 80rpx;
        height: 80rpx;
        border-radius: 100rpx;
        background-color: #f6f6f6;
      }
    }
  }
</style>
